028-implement-strstr.py
problem: ---
problem:

Implement strStr().
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Example 1:
Input: haystack = "hello", needle = "ll"
Output: 2

Example 2:
Input: haystack = "aaaaa", needle = "bba"
Output: -1

Clarification:
What should we return when needle is an empty string? This is a great question to ask during an interview.
For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().
---

-----------------------------------------------------------------------
bug_fixes: ---
bug_fixes:
Replace `haystack[i:i+1]` with `haystack[i:i+l]` on line 6.
Add `return -1` on line 9.
---

-----------------------------------------------------------------------
bug_desc: ---
bug_desc:
On line 6, haystack[i:i+1] is compared to needle. haystack[i:i+1] will return the ith character only. This will result in incorrect behavior if needle is more than one character long. Taking the subset from i to i+l will fix the mistake, i.e., haystack[i:i+l].
On line 9, or after line 8, nothing is returned from the method if a matching needle is not found. This is incorrect behavior as -1 should be returned. Adding `return -1` will fix the mistake.
---

-----------------------------------------------------------------------
line_no: ---
line_no:
6
---

-----------------------------------------------------------------------
buggy_code: ---
buggy_code:
1. class Solution(object):
2.     def strStr(self, haystack, needle):
3.         if needle == ""or needle == haystack: return 0
4.         l = len(needle)
5.         for i in range(0,(len(haystack)-l+1)):
6.             if haystack[i:i+1] == needle:
7.                 return i
8.             print(haystack[i:i+l])
9.             
---

-----------------------------------------------------------------------
correct_code: ---
correct_code:
1. class Solution(object):
2.     def strStr(self, haystack, needle):
3.         if needle == ""or needle == haystack: return 0
4.         l = len(needle)
5.         for i in range(0,(len(haystack)-l+1)):
6.             if haystack[i:i+l] == needle:
7.                 return i
8.             print(haystack[i:i+l])
9.         return -1
10. 
---

-----------------------------------------------------------------------
